//配置路由的地方
import Vue from "vue";
import VueRouter from "vue-router";
//使用插件
Vue.use(VueRouter)
//引入路由组件
import Home from '@/pages/home'
import Login from '@/pages/Login'
import Search from '@/pages/Search'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
//配置路由
export default new VueRouter({
    //配置路由
    routes:[
        
        {
            path:'/home',
            component:Home,
            //添加路由元信息，加个show字段用于控制footer的显示与隐藏
            //meta是固定的
            meta:{show:true},
        },
        {
            path:'/Login',
            component:Login,
            meta:{show:false},
        },
        {
            // 跳转到search 并接收参数searchKeyWord
            // /:searchKeyWord?
            path:'/Search/:keyword?',
            component:Search,
            meta:{show:true},
            name:"Search"
        },
        {
            path:'/Register',
            component:Register,
            meta:{show:false},
        },
        {
            path:'/Detail/:skuid?',            
            component:Detail,
            meta:{show:true},
            name:"Detail"
        },
        {
            path:'/AddCartSuccess',            
            component:AddCartSuccess,
            meta:{show:true},
            name:'AddCartSuccess',
        },
        {
            path:'/ShopCart',            
            component:ShopCart,
            meta:{show:true},
            name:'ShopCart',
        },
        //重定向为主页
        {
            path:'/*',            
            redirect: "/home",
            meta:{show:true},
        },
    ],
    // 滚动行为
    scrollBehavior (to, from, savedPosition) {
        return {y: 0 }
    },
})
